//循环
//数组
const arr = ['a', 'b', 'c', 'd']
for (let i = 0; i < arr.length; i++) {
    const item = arr[i]
    // console.log(item)
}

for (let i in arr) {
    // console.log(i)
    const item = arr[i]
    // console.log(item)
}
//对象或者对象的原型里面有Symbol(Symbol.iterator)键，代表可以调用for of方法
for (let item of arr) {
    // console.log(item)
}

//forEach没有返回值
arr.forEach(function (item, index, array) {
    // console.log(item)
    // console.log(index)
    // console.log(array) 
})

//有返回值，返回值是次调用回调函数的返回值所组成的数组
let arr2 = arr.map(function (item, index, array) {
    // console.log(item)
    // console.log(index)
    // console.log(array)
    return item
})

let forecast = [{
    "date": "8日星期一",
    "high": "高温 28℃",
    "fengli": "<![CDATA[2级]]>",
    "low": "低温 21℃",
    "fengxiang": "西北风",
    "type": "小雨"
}, {
    "date": "9日星期二",
    "high": "高温 30℃",
    "fengli": "<![CDATA[2级]]>",
    "low": "低温 20℃",
    "fengxiang": "西南风",
    "type": "多云"
}, {
    "date": "10日星期三",
    "high": "高温 30℃",
    "fengli": "<![CDATA[1级]]>",
    "low": "低温 21℃",
    "fengxiang": "东南风",
    "type": "晴"
}, {
    "date": "11日星期四",
    "high": "高温 30℃",
    "fengli": "<![CDATA[1级]]>",
    "low": "低温 22℃",
    "fengxiang": "东南风",
    "type": "多云"
}, {
    "date": "12日星期五",
    "high": "高温 30℃",
    "fengli": "<![CDATA[1级]]>",
    "low": "低温 22℃",
    "fengxiang": "西北风",
    "type": "多云"
}]

let arr3 = forecast.map(function(item){
    return `
    <tr>
        <td>${item.date}</td>
        <td>${item.high}</td>
        <td>${item.low}</td>
        <td>${item.type}</td>
        <td>${item.fengxiang}</td>
    </tr>
    `
})
const html = arr3.join('')

let f1 = forecast.find(function(item,index){
    if(item.date === "11日星期四"){
        return true
    }
})

var stus = [
    {stuNum: 1101, name: '曹操', score: 95},
    {stuNum: 1102, name: '吕布', score: 50},
    {stuNum: 1103, name: '貂蝉', score: 65},
    {stuNum: 1104, name: '赵云', score: 70},
    {stuNum: 1105, name: '赵信', score: 85}
];

const zx = stus.find(function(item){
    // if(item.name == '赵信'){
    //     return true
    // }
    return item.name == "赵信"
})

//筛选
const jg = stus.filter(function(item){
    if(item.score >= 60){
        return true
    }
})
//只要有一个成立则返回true
const f = stus.some(function(item){
    return item.score >= 60
})
const f2 = stus.every(function(item){
    return item.score >= 60
})

const listEle = document.querySelectorAll('.item')
const listEle1 = document.getElementsByClassName('item')
console.log(listEle1)
console.log(listEle)
// listEle1.classList.add('red')

HTMLCollection.prototype.forEach = function(cb){
    for(let i=0;i<this.length;i++){
        const item = this[i]
        if(typeof cb === "function"){
            cb(item,i,this)
        }   
    }
}

listEle1.forEach(function(item,index,arr){
    console.log(item)
    console.log(index)
    console.log(arr)
})


// for(let key in listEle){
//     console.log(key)
// }

//HTMLCollection，NodeList转数组

const listArr = Array.from(listEle)
const listArr1 = Array.from(listEle1)

const listArray = [...listEle]
const listArray1 = [...listEle1]